package com.genersoft.iot.vmp.rabbitmq.config;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.genersoft.iot.vmp.gb28181.bean.DeviceMsg;
import org.springframework.amqp.core.Exchange;
import org.springframework.amqp.core.ExchangeBuilder;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.amqp.rabbit.core.RabbitAdmin;
import org.springframework.amqp.support.converter.DefaultClassMapper;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.amqp.support.converter.MessageConverter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author WangPing
 * @Date 2024/10/23
 **/
@Configuration
public class RabbitConfig {



    @Bean
    public MessageConverter jsonMessageConverter() {
        Jackson2JsonMessageConverter converter = new Jackson2JsonMessageConverter();
        DefaultClassMapper classMapper = new DefaultClassMapper();
        // 添加允许的类
        Map<String, Class<?>> idClassMapping = new HashMap<>();
        idClassMapping.put("com.genersoft.iot.vmp.gb28181.bean.DeviceMsg", DeviceMsg.class);
        classMapper.setIdClassMapping(idClassMapping);
        converter.setClassMapper(classMapper);
        return converter;
    }

    @Bean("bootExchange")
    public Exchange getExchange() {
        return ExchangeBuilder
                .topicExchange("device_upload_data_exchange") // 交换机类型
                .durable(true) // 是否持久化
                .build();
    }
}

